﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Itop.YHPC.Model;
using Itop.YHPC.controller;

namespace Itop.YHPC.admin {
    public partial class yhpcOrgTreeAjax : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
            
            string id = Request.QueryString["node"];
            string ret = Newtonsoft.Json.JsonConvert.SerializeObject(getList(id));
            Response.Write(ret);
            Response.End();
        }
        
        List<object> getList(string pid) {

            List<object> list = new List<object>();
            //if (pid == "root") {
            //    list.Add(new  { id = "二级单位", text = "二级单位", cls = "folder" });
            //    list.Add(new  { id = "公司部门", text = "公司部门", cls = "folder" });
            //    list.Add(new  { id = "公司领导", text = "公司领导", cls = "folder" });
            //} else 
            {

                IList<yhpcOrg> orgs=yhpcOrgController.GetList("where parentid='" + pid + "' order by orderid");
                foreach (yhpcOrg org in orgs) {
                    //list.Add(new {id=org.id, cls="file", leaf=true, text=org.dwName });
                    if (org.isgroup == "1") {
                        list.Add(new { id = org.id, cls = "folder", text = org.dwName });
                    } else {
                        list.Add(new { id = org.id, cls = "file", leaf = true, text = org.dwName });
                    }
                }
            }
            return list;
        }
        //class treenode{
        //    public string id;
        //    public string text;
        //    public bool leaf;
        //    public string cls;
        //}
    }
}
